using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;

namespace NoMana.Components.PlayerAvatar
{
    public class UserAvatarAction
    {
       




        public delegate void AnimationComplete();
        public event AnimationComplete OnAnimationComplete;

        private TimeSpan? _animationLengh { get; set; }
        private Timer _animationTime;

        private TimeSpan _timerStart = new TimeSpan(0);

        private IAvatarAnimation _animation;
        public IAvatarAnimation Animation { get { return _animation; } }

        public UserAvatarAction(IAvatarAnimation animation, TimeSpan? animationLengh)
        {
            _animation = animation;
            _animationLengh = animationLengh;



            if (_animationLengh.HasValue)
            {
                _animationTime = new Timer(CheckTimerComplete);
                _animationTime.Change(_animationLengh.Value, _timerStart);
                
            }

        }

        private void CheckTimerComplete(object state)
        {
            if (state is Timer)
            {
                if (OnAnimationComplete != null)
                {
                    _animationTime.Dispose();
                    OnAnimationComplete();
                }
            }
        }
    }
}
